package com.woniu.controller.homepage;

import com.woniu.entity.Distribution;
import com.woniu.entity.Orders;
import com.woniu.entity.Sorting;
import com.woniu.service.homePage.IDistributionTwoService;
import com.woniu.util.ResData;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 配送前端controller层
 * @author 任楷锐
 * @data 2023/3/13 7:51
 */
@RestController
@RequestMapping("/app/distribution")
public class DistributionTwoController {
    @Autowired
    private IDistributionTwoService distributionTwoService;

    //配送员开始配送
    @RequestMapping("startDispatching")
    public ResData<?> startDispatching(@RequestBody Orders orders){
        return distributionTwoService.startDispatching(orders.getStatus(),orders.getDispatcherId(),orders.getId());
    }

    //接单中心的配送人员接单
    @RequestMapping("updateDistributionId")
    public ResData<?> updateDistributionId(@RequestBody Orders orders){
        return distributionTwoService.updateDistributionId(orders.getDispatcherId(),orders.getId());
    }

    //查询工作人员的每日和每月业绩
    @RequestMapping("getOwnPerformance")
    public ResData<?> getOwnPerformance(@RequestBody Orders orders){
        return distributionTwoService.getOwnPerformance(orders.getDispatcherId(),orders.getDistributionBeginTime(),orders.getDistributionEndTime());
    }
    //查询工作人员的个人订单详情
    @RequestMapping("queryOwnDistributionOrders")
    public ResData<?> queryOwnDistributionOrders(Integer dispatcherId){
        return distributionTwoService.queryOwnDistributionOrders(dispatcherId);
    }


    // //查询所有待配送的订单,接单中心的显示
    @RequestMapping("queryAllDistributionOrders")
    public ResData<?> queryAllDistributionOrders(){
        return distributionTwoService.queryAllDistributionOrders();
    }


    //根据手机号查询工作人员所有信息
    @RequestMapping("queryWorkUser")
    public ResData<?> queryWorkUser(String phone){
        return distributionTwoService.queryWorkUser(phone);
    }

    //工作人员根据手机号和密码登录
    @RequestMapping("LoginByPhone")
    public ResData<?> LoginByPhone(String phone,String password){
        return distributionTwoService.LoginByPhone(phone,password);
    }

    //通过手机号获取当前登录的工作人员的dispatcherId
    @RequestMapping("getDispatcherIdByPhone")
    public ResData<?> getDispatcherIdByPhone(String phone){
        return distributionTwoService.getDispatcherIdByPhone(phone);
    }

    //根据手机号修改工作人员密码
    @RequestMapping("updatePasswordByPhone")
    public ResData<?> updatePasswordByPhone(String phone,String password){
        return distributionTwoService.updatePasswordByPhone(phone,password);
    }

    //根据配送员id 和订单号查询所有配送信息
    @RequestMapping("/findDistribution")
    public ResData<?> findDistribution(String orderId,Integer dispatcherId){
        ResData<?> distribution = distributionTwoService.findDistribution(orderId,dispatcherId);
        return distribution;
    }


    //插入配送表信息
    @RequestMapping("/insertDistribution")
    public ResData<?> insertDistribution(@RequestBody Distribution distribution){
        return distributionTwoService.insertDistribution(distribution);

    }

    //修改配送表state订单状态
    @RequestMapping("/updateDistributing")
    public ResData<?> updateDistributing(Integer state,String orderId, String userId){
        return distributionTwoService.updateDistributing(state,orderId,userId);

    }

    //确认收货修改配送表state订单状态
    @RequestMapping("/updateDistributed")
    public ResData<?> updateDistributed(@RequestBody Distribution distribution){
        return distributionTwoService.updateDistributed(distribution.getState(),distribution.getOrderId(),distribution.getUserId());

    }

}
